package threading;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-06-13
 * Time: 20:08
 */
public class ThreadDemo23 {
    public static void main(String[] args) throws InterruptedException {
        AtomicInteger num = new AtomicInteger(0);

        Thread t1 = new Thread(() -> {
            for(int i = 0; i < 50000; i++) {
                //相当于num++
                num.getAndIncrement();

                //相当于++num
                //num.incrementAndGet();
                //相当于num--
                //num.getAndDecrement();
                //相当于--num
                //num.decrementAndGet();
            }
        });

        Thread t2 = new Thread(()-> {
            for(int i = 0; i < 50000; i++) {
                num.getAndIncrement();
            }
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        //get获取数值
        System.out.println(num.get());

    }
}
